var app = getApp(),
  a = app.requirejs("core");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nav: [],
    list: [],
    page:1,
    loaded:false,
    class_id:'',
    integral:0
  },
  onLoad:function(){
    "" == app.getCache("userinfo") && (a.toast('您还没登录呢'),
      setTimeout(function () {
        wx.redirectTo({
          url: "/yb_shop/pages/index/index"
        })
      }, 2e3));
    var that=this;
    that.getlist();
    that.getcate();
  },
  getlist: function () {
    var that = this,
      page = that.data.page,
      class_id = that.data.class_id;
    a.get('Integral/goodslist', { page: page, class_id: class_id}, function (t) {
      if (t.code == 0) {
        if (t.info.length > 0) {
          that.setData({
            list: that.data.list.concat(t.info),
            page: page + 1,
            show: true
          })
          if (t.info.length < 10) {
            that.setData({ loaded: true })
          }
        }
        else {
          that.setData({
            loaded: true,
          })
        }

      } else {
        a.alert(t.msg);
      }
    }, !that.data.show)
  },
  getcate: function () {
    var that = this;
    a.get('Integral/goodscate', {uid: app.getCache('userinfo').uid }, function (t) {
      if (t.code == 0) {
          that.setData({
            nav: t.info.list,
            integral: t.info.integral 
          })
      } else {
       // a.alert(t.msg);
      }
    })
  },
  to_datail:function(e){
    var id=a.pdata(e).id;
    a.jump('goods_info?id='+id);
  },
  change_cate:function(e){
    var class_id=a.pdata(e).id;
    this.setData({
      list: [],
      page: 1,
      class_id: class_id,
      loaded: false
    });
    this.getlist();
  },
  integral_log:function(){
      a.jump('log');
  },
  onPullDownRefresh: function () {
    this.setData({
      list: [],
      page: 1,
      loaded: false
    });
    this.getlist();
    this.getcate();
  },
  onReachBottom: function () {
    this.loaded || this.getlist();
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }

})